home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / checksum.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-15  |  714 b   |  41 lines

  1. #ifndef XPKMASTER_CHECKSUM_C
  2. #define XPKMASTER_CHECKSUM_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        checksum.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: checksum.c 1.2 (31.01.97)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    Simple checksum routines
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   30.01.97 : added new option to cchecksum, became necessary
  15.  1.2   31.01.97 : removed option
  16. */
  17.  
  18. #include <exec/types.h>
  19.  
  20. UBYTE hchecksum(STRPTR ptr, ULONG count)
  21. {
  22.   register UBYTE sum = 0;
  23.  
  24.   while(count-- > 0)
  25.     sum ^= *ptr++;
  26.  
  27.   return sum;
  28. }
  29.  
  30. UWORD cchecksum(ULONG *ptr, ULONG count)
  31. {
  32.   register ULONG sum = 0;
  33.  
  34.   while(count-- > 0)
  35.     sum ^= *ptr++;
  36.  
  37.   return (UWORD) (sum ^ (sum >> 16));
  38. }
  39.  
  40. #endif /* XPKMASTER_CHECKSUM_C */
  41.